#pragma once

namespace Tmpl {

struct EntityMovementPos
{
	Vec2f pos;
	Vec2f facing;
	float speed;
	float size;
};

class Entity;
class EntityMovement
{
public:
	Entity* GetOwner(){return mOwner;}

	void SetSpeed(float speed);
	void SetSize(float size);
	void SetPos(Vec2f pos);
	void SetFacing(Vec2f facing);
	void SetMaxSpeed(float speed){mMaxSpeed = speed;}

	float GetSpeed() const;
	float GetSize() const;
	Vec2f GetPos() const;
	Vec2f GetFacing() const;
	float GetMaxSpeed() const {return mMaxSpeed;}
	float GetNextSpeed() const;
	float GetNextSize() const;
	Vec2f GetNextPos() const;
	Vec2f GetNextFacing() const;

private:
	friend class EntityMovementSystem;
	Entity* mOwner;
	int mMoveId;
	float mMaxSpeed;
};

struct UnitData;
class EntityMovementSystem
{
public:
	static void Init();
	static void Clear();

	static int NewMovement(Entity* owner, Vec2f pos, Vec2f facing, const UnitData& data);
	static void RemoveMovement(int id);
	static EntityMovement* GetMovement(int id);

	static JobHandle Update(JobHandle dependency);
private:
	static void UpdateMovementChunk(int chunk);
	static void SolveOverlapChunk(int chunk);
	static void UpdateGrid();
};

} // namespace Tmpl